package com.ems.controller.supers.questions;

import com.ems.pojo.data.RequestData;
import com.ems.pojo.data.ResultData;
import com.ems.pojo.data.RetunResult;
import com.ems.pojo.data.ReturnPageResult;
import com.ems.pojo.questions.Choose;
import com.ems.pojo.questions.Subject;
import com.ems.service.supers.questions.ChooseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Auther: 伟伟
 * @Date: 2019/10/19
 * @Description: 选择题控制类（多选和单选）
 * @Version: 1.0
 */
@Controller
@CrossOrigin //允许所有请求跨域
@RequestMapping("/chooseController")
public class ChooseController {

    @Autowired
    @Qualifier("chooseService")
    private ChooseService chooseService;


    /**
     * 添加选择题
     * @param choose
     * @return
     */
    @ResponseBody
    @RequestMapping("/addChoose")
    public ResultData addChoose(@RequestBody Choose choose){
        chooseService.addNewChoose(choose);
        return RetunResult.AssemblyData();
    }

    /**
     * 删除指定的选择题
     * @param chooseList
     * @return
     */
    @ResponseBody
    @RequestMapping("/deleteChoose")
    public ResultData deleteChoose(@RequestBody List<Choose> chooseList){
        chooseService.deleteChoose(chooseList);
        return RetunResult.AssemblyData();
    }

    /**
     * 修改指定的选择题
     * @param choose
     * @return
     */
    @ResponseBody
    @RequestMapping("/updateChoose")
    public ResultData updateChoose(@RequestBody Choose choose){
        chooseService.updateChoose(choose);
        return RetunResult.AssemblyData();
    }

    /**
     * 按照条件查询指定的选择题
     * @param requestData
     * @return
     */
    @ResponseBody
    @RequestMapping("/findChoose")
    public ResultData findChoose(@RequestBody RequestData requestData){
        ReturnPageResult.setPageHelperInfo(requestData);

        List<Choose> list = chooseService.findChoose(requestData);

        return ReturnPageResult.AssemblyData(list);
    }

    /**
     * 根据id查询对应的选择题
     * @param choose
     * @return
     */
    @ResponseBody
    @RequestMapping("/getChooseById")
    public ResultData getChooseById(@RequestBody Choose choose){
        return RetunResult.AssemblyData();
    }


}
